#include "dialog.h"
#include "ui_dialog.h"
const static double PI=3.1416;
Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
}

Dialog::~Dialog()
{
    delete ui;
}


/*
wzb: silt clay sand size
https://cn.bing.com/search?q=silt%20clay%20sand%20size&qs=n&form=QBRE&=%25eManage%20Your%20Search%20History%25E&sp=-1&pq=silt%20clay%20sand%20size&sc=8-19&sk=&cvid=1C5FB37450374E89A95E3B77E08483D0

*/
QString Dialog::getISSSResult(double sand, double silt, double clay)

      {

           QString soilType = "不能识别的类型";

           if ((sand < 0 || sand > 100)|| (silt < 0 || silt > 100) || (clay < 0 || clay > 100))

           {

               return "某项粒度含量不在有效范围";

           }else if ((sand + silt + clay <99.999999) || (sand + silt + clay > 100.000001))

           {

               return "粒度含量之和不等于100%";

           }else{

               if(silt > 45 && clay<= 15){

               soilType = "粉壤土";

               }else if(silt > 45&& clay <= 25 && clay > 15){

               soilType = "粉黏壤土";

               }else if(silt > 45&& clay > 25 && clay <= 45){

               soilType = "粉黏土";

               }else if(clay > 45&& clay <= 65){

               soilType = "黏土";

               }else if(clay > 65){

               soilType = "重黏土";

               }else if(sand <= 55&& clay > 25 && clay <= 45 && silt <= 45){

               soilType = "壤黏土";

               }else if(sand > 55&& clay > 25){

               soilType = "砂黏土";

               }else if(sand <= 55&& clay > 15 && clay <= 25 && silt <= 45){

               soilType = "黏壤土";

               }else if(sand > 55&& clay > 15 && clay <= 25){

               soilType = "砂黏壤土";

               }else if(sand <= 55&& clay <= 15 && silt <= 45){

               soilType = "壤土";

               }else if(sand > 55&& sand <= 85 && clay <= 15){

               soilType = "砂壤土";

               }else if(sand > clay * 2 +85){

               soilType = "砂土";

               }else{

               soilType = "壤砂土";

               }

           }

           return soilType;

      }


void Dialog::on_pushButtonSearch_clicked()
{
   double sand= ui->spinBox1_3->text().toDouble();
   double silt= ui->spinBox1_2->text().toDouble();
   double clay= ui->spinBox1_1->text().toDouble();
   QString res= getISSSResult( sand,  silt,  clay);


QMessageBox::information(this,"Soil",res,QMessageBox::Yes);
}

